<?php

function sechungpark($com, &$output, $this1, $style="", $username=null) {
    
    foreach ($com as $com1) {
      $output.="<div class='post1' style='background-color:".$style."' id='".$com1['Comment']['id']."ab'>";
      $output.=$com1['Comment']['id']."<br/>";
     
      $output.="<b>".$com1['Comment']['name']."</b><span style='font-size:10px; color:gray;'> -- ID:".$com1['Comment']['anonid']." <span>".($com1['Comment']['up']-$com1['Comment']['down'])."</span> points</span>";
      $output.="<span>";
      
      $output.='<a href="javascript:void(0)" onclick="return updown('.$com1['Comment']['id'].',1, this)" class="updown"><b>↑</b></a>';
      $output.='<a href="javascript:void(0)" onclick="return updown('.$com1['Comment']['id'].',-1, this)" class="updown"><b>↓</b></a></span>';
      $tags1="";
      if ($style!='#F7F7F8')
         $output.='<div class="tags1" id="'.$com1['Comment']['id'].'abc"';
      else
         $output.='<div class="tags1a" id="'.$com1['Comment']['id'].'abc"';
      $output.='>';
      
      if (count($com1['Tag']) > 0) {
  
    $output.='<b>Tags:</b>';
    
    if (isset($username)) 
        $output.='<a href ="javascript:void(0)" onclick="return editTags(this)" class="moreless"> [Edit]</a>';
    $output.='<span class="tags2">';
    
    foreach ($com1['Tag'] as $tag) {
            if (strpos($tag['tag'],"board:")!==false)
                     $output.="<div><a class='boardLink' href='/urp/posts/search/?search=".$tag['tag']."'>".$tag['tag']."</a></div>, ";
                 else if (strpos($tag['tag'],"test:")!==false)
                     $output.="<div>a class='boardLink1' href='/urp/posts/search/?search=".$tag['tag']."'>".$tag['tag']."</a></div>, ";
                 else
                     $output.="<div><a href='/urp/posts/search/?search=".$tag['tag']."' >".$tag['tag']."</a></div>, ";
          $tags1.=$tag['tag']." ";
          }
     $output.='</span>';
   
        }
        else {
            if (isset($username)) 
                $output.="<a href='javascript:void(0);' onclick='return showTags(this);' style='font-size:10px;'>Tag me!</a>";
        }
      
   
      $output.="<div class='tag2'  style='display:none'>";
      $output.='<form action="/urp/tags/add" class="addTags" method="post" accept-charset="utf-8">
        <input type="hidden" name="_method" value="POST" />
      <div class="input text" style="display:inline; clear:none;">
        <input type="hidden" name="data[Comment][id]" value="'.$com1['Comment']['id'].'"/>
        <input name="data[Tag][tag]" id="Tagtag" type="text" value="'.$tags1.'"class="search1"/>
       
      </div>
      <div id="suggest1">
           
      </div>
      <div>   
        <input type="checkbox" name="data[Suggest]" id="suggest" checked="checked" value="1"> Suggest Tags?
      </div>
<div class="submit" style="display:inline; clear:none;">
          <input type="submit" id="tagSubmit" value="Add Tags"></div></form>';
      
//     echo '<div id="tags" style="display:none;">
//   <form action="/urp/tags/add" id="TagAddForm" method="post" accept-charset="utf-8"><div style="display:none;">
//      <input type="hidden" name="_method" value="POST"></div>    <input type="hidden" name="data[Post][id]" value="7" id="PostId">  
//      <div class="input textarea"><label for="TagTag"></label><textarea name="data[Tag][tag]" cols="30" rows="6" id="TagTag">
//          adsafdadsf do i who says sean is a belly boy asdf </textarea></div>   
//              <div class="submit"><input type="submit" value="Add Tag"></div></form>  
//              </div>';
      $output.="</div></div>";
      $output.="<p class='commentText'>";
      
       // "  <a href='#'class='updown' onclick=''>↓</a><br/>";
      
//      echo $this->Html->link('↑',    array('controller' => 'Comments', 'action' => 'up', $com1['Comment']['id']),    array('class'=>'updown'),    "Are you sure you want to upvote?");
//     echo $this->Html->link('Enter', '/pages/home', array('class' => 'butt
      
//      echo $this->Html->link('↑',    array('controller' => 'Comments', 'action' => 'up', $com1['Comment']['id']),    array('class'=>'updown'),    "Are you sure you want to upvote?");
//     echo $this->Html->link('Enter', '/pages/home', array('class' => 'buton', 'target' => '_blank'));
//              "<a href='#' class='updown' onclick=''></a><a href='#'class='updown' onclick=''>↓</a><br/>";
      
      $output.=bb_code($com1['Comment']['text']);
//      $this1->element('parse_text', array('com'=>  $com1['Comment']['text']));
      
     
       
     $output.="<br/></p>";
      
      $output.="<div class='replylinks'>
          <a href=''>Permalink</a>
          <a href='javascript:void(0)' onclick='return reply(".$com1['Comment']['id'].", this)'>Reply</a>
              <a href='javascript:void(0)' onclick='return showOptions(this)'>></a>
              <span style='display:none'> <a href='javascript:void(0)' onclick='return deleteComment(this,".$com1['Comment']['id'].")'>Delete</a><a href='javascript:void(0)' onclick='return editComment(this)'>Edit</a></span>
              </div><br/>";
     
      $output.="<div class='post'>";
      if (isset($com1['Comment']['replies'])) {
         
          if ($style=="")
              $style1="#F7F7F8";
          else
              $style1="";
          sechungpark($com1['Comment']['replies'], $output, $this1, $style1, $username);
          }
      
        $output.="</div>";
        
 $output.="</div>";
        
      }
 }

echo $this->element('bbcode');
if (isset($newcom))   
 echo "<span id='newcomment' style='display:none'>".$newcom."</span>";  
if (isset($username))
    sechungpark($com,$output,$this, '', $username);
else
    sechungpark($com,$output,$this, '', null);
echo $output;
?>